package com.jqr.activity.mycoroutine

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.TextView

import androidx.activity.viewModels
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope



import com.jqr.activity.mycoroutine.viewmodels.MainViewModel
import kotlinx.coroutines.DelicateCoroutinesApi


class MainActivity5 : AppCompatActivity() {
    private lateinit var   mainViewModel :MainViewModel
    @OptIn(DelicateCoroutinesApi::class)
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main1)
        mainViewModel = ViewModelProvider(this).get(MainViewModel::class.java)
        val nameTextView=findViewById<TextView>(R.id.textView)

        findViewById<Button>(R.id.btnClick).setOnClickListener {

            mainViewModel.getArticles()
        }

        mainViewModel.articleLiveData.observe(this,{
            nameTextView.text=it.msg
        })

    }
}



